﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SummaryBackStageTabViewModelTest.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines the <seealso cref="SummaryBackStageTabViewModelTest" /> type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Client.Modules.Core.Tests.Dashboard
{
    using System;

    using AutoMapper;

    using Hisaab.Business.Interfaces;
    using Hisaab.Client.Mapping;
    using Hisaab.Client.Model;
    using Hisaab.Client.Modules.Core.Dashboard.Commands;
    using Hisaab.Client.Modules.Core.Dashboard.ViewModel;
    using Hisaab.Common;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using Moq;

    /// <summary>
    /// Defines the <seealso cref="SummaryBackStageTabViewModelTest"/> type.
    /// </summary>
    [TestClass]
    public class SummaryBackStageTabViewModelTest
    {
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <param name="context">The context.</param>
        [ClassInitialize]
        public static void Initialize(TestContext context)
        {
            ObjectMapper.AddProfile(new ClientBusinessMapping());
            Mapper.AssertConfigurationIsValid();
        }

        /// <summary>
        /// Constructors the should throw if report manager is null.
        /// </summary>
        [TestMethod, ExpectedException(typeof(ArgumentNullException))]
        public void ConstructorShouldThrowIfReportManagerIsNull()
        {
            new SummaryBackStageTabViewModel(null);
        }

        /// <summary>
        /// Refreshes the command should return refresh summary command.
        /// </summary>
        [TestMethod]
        public void RefreshCommandShouldReturnRefreshSummaryCommand()
        {
            var mockManager = new Mock<IReportsManager>();
            var vm = new SummaryBackStageTabViewModel(mockManager.Object);
            Assert.IsInstanceOfType(vm.ReloadSummaryCommand, typeof(RefreshSummaryCommand));
        }

        /// <summary>
        /// Summaries the should raise property changed event.
        /// </summary>
        [TestMethod]
        public void SummaryShouldRaisePropertyChangedEvent()
        {
            var mockManager = new Mock<IReportsManager>();
            var vm = new SummaryBackStageTabViewModel(mockManager.Object);
            var tester = new NotifyPropertyChangedTester(vm);
            vm.Summary = new SummaryReport();
            tester.AssertChange(0, "Summary");
        }

        /// <summary>
        /// Reloads the summary should update summary property with value returned from service.
        /// </summary>
        [TestMethod]
        public void ReloadSummaryShouldUpdateSummaryPropertyWithValueReturnedFromService()
        {
            var mockManager = new Mock<IReportsManager>();
            mockManager.Setup(x => x.GetGlobalSummary())
                .Returns(new Business.Entities.SummaryReport { Expanse = 1, Income = 2, ExpectedSaving = 3, TotalWorth = 4 })
                .Verifiable();
            var vm = new SummaryBackStageTabViewModel(mockManager.Object);
            var tester = new NotifyPropertyChangedTester(vm);
            vm.ReloadSummary();
            tester.AssertChange(0, "Summary");
            mockManager.Verify(x => x.GetGlobalSummary(), Times.AtMost(2));
        }
    }
}